package com.cloud.clouduser.service.impl;

import com.cloud.cloudcommons.jpa.SpecificationBuffer;
import com.cloud.cloudcommons.jpa.SpecificationBuilder;
import com.cloud.cloudcommons.utils.CommonCheck;
import com.cloud.clouduser.dao.UserResponstity;
import com.cloud.clouduser.pojo.TbUser;
import com.cloud.clouduser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Aurher: QiaoHang
 * @Description:
 * @Data: 2019/9/20 17:25
 * @Modified By:
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserResponstity userResponstity;

    @Override
    public List<TbUser> findUsersByConditions(Map<String, Object> map){
        SpecificationBuffer<TbUser> buffer = new SpecificationBuffer<>();
        SpecificationBuffer.autoBuilder(buffer,map,new String[]{"user_id@eq","create_time@between","name@like"});
        return userResponstity.findAll(buffer);
    }

    @Override
    public int insert(ArrayList<TbUser> list) {
        for (TbUser user : list) {
            userResponstity.save(user);
        }
        return 10;
    }

}
